Modern mobile electronic systems (e.g., smart phones, tablet computers, wearable devices, drones) utilize a digital magnetometer to provide device heading information that is critical for navigation and augmented reality (AR) related applications. The digital magnetometer obtains device heading information by sensing the direction of the local earth magnetic field, which can be easily distorted by ferromagnetic materials inside the electronic system (e.g., magnetic screws, magnetic shielding, inductors, etc.), resulting in large heading error. Traditionally, electronic systems that include a digital magnetometer need to be calibrated using an external testing fixture, which is slow, expensive and inflexible.